#define ReleaseType=GetEnv("ReleaseType")
#define SetupFileName=GetEnv("SetupFileName")

#include "ModifyPath.iss"

[Setup]
AppId=lxdbexpinfpro
AppName=Luxena dbExpress driver for Informix Pro
AppVerName=Luxena dbExpress driver for Informix Pro __VersionHigh__.__VersionMinor__.__VersionInternal__ {#ReleaseType} version
AppPublisher=Luxena Software Company
AppPublisherURL=http://www.luxena.com
AppSupportURL=http://www.luxena.com
AppUpdatesURL=http://www.luxena.com
DefaultDirName={pf}\Luxena\dbExpress Informix
DisableProgramGroupPage=yes
SourceDir=L:\Products\dbExpress_Informix_Pro\Version
OutputDir=L:\Products\dbExpress_Informix_Pro\Install\bin
OutputBaseFilename={#SetupFileName}
LicenseFile=license.txt
InfoBeforeFile=readme.win32.txt
InfoAfterFile=history.txt
#if ReleaseType == "Trial"
Compression=zip/9
#else
Compression=none
#endif

[LangOptions]
LanguageName=English
LanguageID=$0409
WelcomeFontName=Tahoma
WelcomeFontSize=10
DialogFontName=Tahoma
DialogFontSize=8

[Components]
Name: "files"; Description: "dbExpress driver for Informix Pro files"
Name: "files\bin"; Description: "Binaries"
Name: "files\bin\driver"; Description: "Driver library"; Types: full compact; Flags: restart
Name: "files\bin\bridge"; Description: "Interface extension bridge for Delphi.NET"; Types: full compact; Flags: restart
Name: "files\demos"; Description: "Demos"; Types: full
Name: "files\doc"; Description: "Manual"; Types: full compact
#if ReleaseType == "Sources"
Name: "files\source"; Description: "Sources"; Types: full
#endif


[Files]
Source: "bin\lxdbexpinfpro.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: files\bin\driver
Source: "bin\DBXInfExtIntf.dll"; DestDir: "{app}\bin"; Flags: ignoreversion; Components: files\bin\bridge
Source: "demos\interruptsql\*"; DestDir: "{app}\demos\interruptsql"; Flags: ignoreversion; Components: files\demos
Source: "demos\superstores_demo\*"; DestDir: "{app}\demos\superstores_demo"; Flags: ignoreversion; Components: files\demos
Source: "doc\*"; DestDir: "{app}\doc"; Flags: ignoreversion recursesubdirs; Components: files\doc
#if ReleaseType == "Sources"
Source: "source\*"; DestDir: "{app}\source"; Flags: ignoreversion recursesubdirs; Components: files\source
#else
Source: "source\DBXInfExt.pas"; DestDir: "{app}\source"; Flags: ignoreversion; Components: files\bin
#endif
Source: "history.txt"; DestDir: "{app}"; Flags: ignoreversion; Components: files
Source: "license.txt"; DestDir: "{app}"; Flags: ignoreversion; Components: files
Source: "readme.win32.txt"; DestDir: "{app}"; Flags: ignoreversion isreadme; Components: files


[_ISTool]
EnableISX=true


[Code]
procedure SetCommonIniEntries(Section, FileName: string);
begin
  SetIniString(Section, 'HostName', 'InformixServer=server; WaitOnLocks=False; Trim Char=False; money=currency; decimal=bcd; int8=fmtbcd; lvarchar=string', FileName);
  SetIniString(Section, 'DataBase', 'database', FileName);
  SetIniString(Section, 'User_Name', 'user', FileName);
  SetIniString(Section, 'Password', 'password', FileName);
  SetIniString(Section, 'AutoCommit', 'True', FileName);
  SetIniString(Section, 'BlobSize', '-1', FileName);
  SetIniString(Section, 'CommitRetain', 'True', FileName);
  SetIniString(Section, 'InformixLuxena TransIsolation', 'ReadCommitted', FileName);
end;

procedure UpdateDriversIni(FileName: string; Install: Boolean);
begin
  if FileExists(FileName) then
    if not Install then
    begin
      DeleteIniEntry('Installed Drivers', 'InformixLuxena', FileName)
      DeleteIniSection('InformixLuxena', FileName);
      DeleteIniSection('InformixLuxena TransIsolation', FileName);
    end else
    begin
      SetIniString('Installed Drivers', 'InformixLuxena', '1', FileName);

      SetIniString('InformixLuxena', 'LibraryName', 'lxdbexpinfpro.dll', FileName);
      SetIniString('InformixLuxena', 'VendorLib', 'isqlt09a.dll', FileName);
      SetIniString('InformixLuxena', 'GetDriverFunc', 'getInformixDriver', FileName);

      SetCommonIniEntries('InformixLuxena', FileName);

      SetIniString('InformixLuxena TransIsolation', 'DirtyRead', '0', FileName);
      SetIniString('InformixLuxena TransIsolation', 'ReadCommitted', '1', FileName);
      SetIniString('InformixLuxena TransIsolation', 'RepeatableRead', '2', FileName);
    end;
end;

procedure UpdateConnectionsIni(FileName: string; Install: Boolean);
begin
  if FileExists(FileName) then
    if not Install then
      DeleteIniSection('InformixLuxenaConnection', FileName)
    else
    begin
      SetIniString('InformixLuxenaConnection', 'DriverName', 'InformixLuxena', FileName);
      SetCommonIniEntries('InformixLuxenaConnection', FileName);
    end;
end;

procedure UpdateIniFiles(SubKeyName, DefaultDir: string; Install: Boolean);
var
  FileName: string;
begin
  if not RegQueryStringValue(HKEY_CURRENT_USER, SubKeyName, 'Driver Registry File', FileName) then
    if not RegQueryStringValue(HKEY_LOCAL_MACHINE, SubKeyName, 'Driver Registry File', FileName) then
      FileName := DefaultDir + '\dbxdrivers.ini';
  UpdateDriversIni(FileName, Install);

  if not RegQueryStringValue(HKEY_CURRENT_USER, SubKeyName, 'Connection Registry File', FileName) then
    if not RegQueryStringValue(HKEY_LOCAL_MACHINE, SubKeyName, 'Connection Registry File', FileName) then
      FileName := DefaultDir + '\dbxconnections.ini';
  UpdateConnectionsIni(FileName, Install);
end;

procedure UpdateAllIniFiles(Install: Boolean);
begin
  // Delphi 6, 7
  UpdateIniFiles('SOFTWARE\Borland\DBExpress', ExpandConstant('{cf}') + '\Borland Shared\DBExpress', Install);
  // Delphi 8, 2005
  UpdateIniFiles('SOFTWARE\Borland\BDS\DBExpress', ExpandConstant('{cf}') + '\Borland Shared\BDS\dbExpress', Install);
  // Delphi 2006
  UpdateIniFiles('SOFTWARE\Borland\BDS\4.0\DBExpress', ExpandConstant('{pf}') + '\Borland\BDS\4.0\dbExpress', Install);
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    ModifyPath('{app}\bin', pmAddToEnd, psAllUsers);
    UpdateAllIniFiles(True);
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    UpdateAllIniFiles(False);
    ModifyPath('{app}\bin', pmRemove, psAllUsers);
  end;
end;

